package com.zkx.fssb.controller.server;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkx.fssb.domain.dto.GiftboxDto;
import com.zkx.fssb.domain.po.Flower;
import com.zkx.fssb.domain.po.Giftbox;
import com.zkx.fssb.result.PageQuery;
import com.zkx.fssb.result.Result;
import com.zkx.fssb.service.GiftboxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController("serverGiftboxController")
@RequestMapping("/server/giftbox")
public class GiftboxController {

    @Autowired
    private GiftboxService giftboxService;

    /**
     * 礼盒分页查询
     *
     * @param pageQuery
     *
     * @return
     */
    @GetMapping("/page")
    public Result<Page> page(PageQuery pageQuery) {
        Page page = giftboxService.customPage(pageQuery);

        return Result.success(page);

    }

    /**
     * 新增礼盒
     * @param giftboxDto
     * @return
     */
    @PostMapping
    public Result saveGiftbox(@RequestBody GiftboxDto giftboxDto){
       giftboxService.customeSave(giftboxDto);
       return Result.success("新增礼盒成功");
    }

    /**
     * 根据id回显礼盒数据
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public Result<GiftboxDto> getById(Integer giftboxId){
        GiftboxDto giftboxDto = new GiftboxDto();
        Giftbox giftbox = giftboxService.getById(giftboxId);
        BeanUtils.copyProperties(giftbox,giftboxDto);
        return Result.success(giftboxDto);


    }

    /**
     * 更新礼盒
     * @param giftboxDto
     * @return
     */
    @PutMapping
    public Result updateGiftbox(@RequestBody GiftboxDto giftboxDto){
        giftboxService.customUpdateGiftbox(giftboxDto);

        return Result.success("更新礼盒成功");
    }

    @DeleteMapping
    public Result removeGiftbox(Integer giftboxId){
        giftboxService.removeById(giftboxId);
        return Result.success("删除礼盒成功");

    }




}
